// pages/my/invoice/invoice/invoiceInfo.js
var app = getApp(), api = require("../../../../api.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 1,
    winHeight: '',
    imgheights: [1288,1690],
    raidoItem:[{
      name:'person',
      value:'个人/非企业单位',
      checked: true
    },{
      name: 'company',
      value: '企业单位'
    }],
    province:'',
    city:'',
    area:'',
    show:false,
    isShow:false,
    order_list:[],
    order_price:0.00
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
    var _this=this;
    _this.setData({
      order_list: app.globalData.order_list,
      order_price: app.globalData.order_price
    })
    let res = wx.getSystemInfoSync()
    this.setData({
      winHeight: res.windowHeight+530
    })
  },
  chooseAddress: function () {
    var that = this;
    that.setData({
      show: true
    })
  },
  details: function (e) {

    var title = e.currentTarget.dataset.title, genre = e.currentTarget.dataset.genre;
    wx.navigateTo({
      url: '../../../details/details?title=' + title + '&genre=' + genre,
    })
  },
  formSubmit: function (res){
    
    var _this = this, formData = res.detail.value, type = _this.data.isShow ? 2 : 1, tax_no = formData.tax_no ? formData.tax_no:null;
    
    app.request({
      url:api.tax_apply,
      header: {"content-type":'application/json'} ,
      data:{
        headline: formData.headline,
        tax_content: formData.tax_content,
        price:_this.data.order_price,
        tax_address: formData.tax_address,
        order_id:_this.data.order_list,
        mobile:formData.mobile,
        bank_name: formData.bank_name,
        bank_no: formData.bank_no,
        username:formData.username,
        province: _this.data.province,
        city: _this.data.city,
        area: _this.data.area,
        address_details: formData.address_details,
        tax_no: tax_no,
        type:type,
        phone: formData.phone
      },
      method:'POST',
      success:function(res){
        if(res.code==0){
          wx.showToast({
            title: '提交成功',
            success: function () {
              setTimeout(function () {
                wx.navigateBack({

                })
              }, 1000)
            }
          })
        }
      }
    })
  },
  // 选择个人或企业单位
  changType:function(e){
    var that = this;
    if (e.detail.value === 'company'){
      that.setData({
        isShow: true
      })
    }else{
      that.setData({
        isShow: false
      })
    }
  },
  // 选择地区
  sureSelectAreaListener: function (e) {
    var that = this;
    that.setData({
      show: false,
      province: e.detail.currentTarget.dataset.province,
      city: e.detail.currentTarget.dataset.city,
      area: e.detail.currentTarget.dataset.area
    })
  },

  swiperTab: function (e) {
    var that = this;
    that.setData({
      currentTab: e.detail.current
    });
  },
  cilckTab: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})